package com.example.peibei.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.example.peibei.R;
import com.example.peibei.ui.activity.WebviewActivity;

public class BannerFragment extends Fragment {

    ImageView img;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_banner,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        img= view.findViewById(R.id.iv_img);
        String imgUrl = getArguments().getString("imgUrl");
        String htmlUrl = getArguments().getString("htmlUrl");
        System.out.println("轮播图："+imgUrl);
        Glide.with(getContext()).load(imgUrl).into(img);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("htmlUrl", htmlUrl);
                Intent it =new Intent(v.getContext(), WebviewActivity.class);
                it.putExtras(bundle);
                startActivity(it);
            }
        });
    }
}
